<?php

class Admin_ContactsController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
    	$contacts = new Application_Model_DbTable_Contacts( );
       	$this->view->contacts = $contacts->fetchAll();
    }

    public function editAction()
    {
    	$id = (int)$this->_request->getParam( 'id' );
    	$this->view->pageTitle = 'עריכת פניה';
    	$_contact = new Application_Model_DbTable_Contacts( );
        $contactDetails = $_contact->find( $id )->current( )->toArray( );
        $formParams = array(
    		'legendLabel' => $this->view->pageTitle 
    	);
        $this->view->form = new Application_Form_Contact ( $formParams );
        $this->view->form->setDefaults($contactDetails);
      	if($this->_request->isPost( )){
        	if($this->view->form->isValid( $this->_request->getPost( ))){
        		$_model =  new Admin_Model_Contact();
        		$_model->save( $this->view->form->getValues( ) );
        		$this->_forward('index');		
        	}
        }
    }
}